﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">
		<title>采购入库新增</title>
		<link rel="stylesheet" type="text/css"
			href="<%=request.getContextPath()%>/css/public.css">

		<script language="JavaScript"
			src="<%=request.getContextPath()%>/js/public.js"></script>
		<script type="text/javascript"
			src="<%=request.getContextPath()%>/js/date1.js"></script>
		<script type="text/javascript" charset="UTF-8"
			src="<%=request.getContextPath()%>/js/stockInStorage.js"></script>
		<script type="text/javascript" charset="UTF-8"
			src="<%=request.getContextPath()%>/js/stockorder.js"></script>
		<script type="text/javascript" charset="UTF-8"
			src="<%=request.getContextPath()%>/js/ajax.js"></script>
		<script type="text/javascript" charset="UTF-8"
			src="<%=request.getContextPath()%>/js/validate.js"></script>
		<script type="text/javascript" charset="UTF-8"
			src="<%= request.getContextPath() %>/js/date.js"></script>
		<script type="text/javascript">
			function validate(){
				//供应商名称
				var supplierName = document.getElementById('supplierName');
				//采购入库单编号
				var code = document.getElementById('code');
				//部门经理
				var managerName = document.getElementById('managerName');
				//部门名称
				var departmentName = document.getElementById('departmentName');
				//业务员名称
				var businesserName = document.getElementById('businesserName');
				//验收人员
				var acceptancerName = document.getElementById('acceptancerName');
				//表格
				var mbody = document.getElementById('mbody');
				
				//验证供应商名称
				if(!isNotNull(supplierName,'供应商'))
					return false ;	
				//验证采购订单编号
				if(!isNotNull(code,'编号')||!f_check_number(code,'编号')||!f_check_NumLength(code,'编号'))
					return false ;
				//验证主管
				if(!isNotNull(managerName,'主管'))
					return false ;
				//验证验收人员
				if(!isNotNull(acceptancerName,'验收'))
					return false ;	
				//验证业务员名称
				if(!isNotNull(businesserName,'业务员'))
					return false ;	
				
				if(mbody.rows.length<=0){
					alert("请添加明细");
					return false;			
				}
				else{
					for(var i=0;i<mbody.rows.length;i++){
						//物料代码
						var materialCode = document.getElementById('materialCode'+i);
						//收料仓库
						var storageName = document.getElementById('storageName' + i);
						//计量单位
						var measureUnitName = document.getElementById('measureUnitName'+i);
						//应收数量
						var shouldAmount = document.getElementById('shouldAmount'+i);
						//实收数量
						var factAmount = document.getElementById('factAmount' + i);
						//单价
						var unitPrice = document.getElementById('unitPrice'+i);
						//金额
						var money = document.getElementById('money'+i);						
						
						var rowIndex = i+1 ;
						//验证物料代码					
						if(!(isNotNull(materialCode,'第'+rowIndex+'行:'+'物料代码')&&f_check_ZhOrNumOrLett(materialCode,'第'+rowIndex+'行:'+'物料代码')))
							return false;
						//验证收料仓库
						if(!isNotNull(storageName,'第'+rowIndex+'行:'+'收料仓库')) 
							return false;
						//计量单位
						if(!(isNotNull(measureUnitName,'第'+rowIndex+'行:'+'单位')&&f_check_ZhOrNumOrLett(measureUnitName,'第'+rowIndex+'行:'+'单位')))
							return false;
						//单价
						if(!(isNotNull(unitPrice,'第'+rowIndex+'行:'+'单价')&&f_check_float(unitPrice,'第'+rowIndex+'行:'+'单价')))
							return false;
						if(parseFloat(unitPrice.value) <= 0) {
							alert('第' + rowIndex + '行:' + '单价必须为正值！');
							return false;
						}
						//应收数量
						if(!(isNotNull(shouldAmount,'第'+rowIndex+'行:'+'应收数量')&&f_check_float(shouldAmount,'第'+rowIndex+'行:'+'应收数量')))
							return false;
						//实收数量
						if(!(isNotNull(factAmount,'第'+rowIndex+'行:'+'实收数量')&&f_check_float(factAmount,'第'+rowIndex+'行:'+'实收数量')))
							return false;
						if(parseFloat(factAmount.value) <= 0) {
							alert('第' + rowIndex + '行:' + '实收数量必须为正值！');
							return false;
						}
						//金额
						if(!(isNotNull(money,'第'+rowIndex+'行:'+'金额')&&f_check_float(money,'第'+rowIndex+'行:'+'金额')))
							return false;
							
					}				
				}
			}
		
		</script>
	</head>
	<body>
		<div id="info_all">
			<div id="info_top">
				采购入库新增
			</div>
			<!-- 主输入区 -->
			<!-- 功能按钮 -->

			<s:form action="addStockInStorage.action" method="post"
				theme="simple" onsubmit="return validate()">
				<div id="info_main">
					<!-- 查询栏 -->

					<div id="info_input">
						<hr>
						<table>
							<tr>
								<td width="60px">
									红蓝字
								</td>
								<td width="130px">
									<s:select list="#{'1':'蓝字', '2':'红字'}"
										name="stockInStorage.tag"></s:select>
								</td>
								<td width="60px">
									供应商(*)
								</td>
								<td width="130px">
									<s:textfield name="" size="12" id="supplierName" readonly="true"></s:textfield>
									<s:hidden name="stockInStorage.supplierId" id="supplierId"></s:hidden>
									<img src="<%=request.getContextPath()%>/images/kookup.gif"
										style="cursor: hand"
										onclick="openWin('supplierSelect.action','supplier',750,700,0)">
								</td>
								<td width="50px">
									日期(*)
								</td>
								<td width="130px">
									<s:textfield name="stockInStorage.inStorageDate" size="12"
										cssStyle="cursor:hand" readonly="true"
										onclick="calendar.setHook(this)"></s:textfield>
								</td>
								<td width="30px">
									编号
								</td>
								<td width="130px">
									<s:textfield name="stockInStorage.inStorageCode" size="12"
										id="code"></s:textfield>
								</td>
								<td width="74px">
									源单类型(*)
								</td>
								<td width="130px">
									<s:select
										list="#{'0':'无源单', '1':'采购订单', '2':'采购发票', '3':'蓝字采购入库单'}"
										name="stockInStorage.sourceBillType"></s:select>
								</td>
							</tr>
							<tr>
								<td>
									选单号
								</td>
								<td width="130px">
									<input type="text" size="12" readonly="true"/>
									<input type="image"
										src="<%=request.getContextPath()%>/images/kookup.gif" />
								</td>

								<td>
									采购方式(*)
								</td>
								<td>
									<s:select list="#{'1':'现购', '2':'赊购'}"
										name="stockInStorage.stockWay"></s:select>
								</td>

								<td>
									保管
								</td>
								<td>
									<s:hidden id="candiateId"></s:hidden>
									<s:hidden id="candiateName"></s:hidden>
									<s:hidden name="stockInStorage.protectorId" id="protextorId"></s:hidden>
									<s:textfield name="" size="12" id="protextorName" readonly="true"></s:textfield>
									<img src="<%=request.getContextPath()%>/images/kookup.gif"
										style="cursor: hand"
										onclick="multiSelect2('candiateName', 'candiateId', 'protextorName', 'protextorId', 'selectMultiCandiate.action', 'candiate', 700, 800, 0)">
								</td>
								<td>
									主管
								</td>
								<td>
									<s:hidden name="stockInStorage.managerId" id="managerId"></s:hidden>
									<s:textfield name="" id="managerName" size="12" readonly="true"></s:textfield>
									<img src="<%=request.getContextPath()%>/images/kookup.gif"
										style="cursor: hand"
										onclick="multiSelect2('candiateName', 'candiateId', 'managerName', 'managerId', 'selectMultiCandiate.action', 'candiate', 700, 800, 0)">
								</td>
								<td>
									部门
								</td>
								<td>
									<s:hidden name="stockInStorage.departmentId" id="departmentId"></s:hidden>
									<s:textfield name="" size="12" id="departmentName" readonly="true"></s:textfield>
									<img src="<%=request.getContextPath()%>/images/kookup.gif"
										style="cursor: hand"
										onclick="openWin('selectDepartment.action', 'department', 500, 600, 0)">
								</td>
							</tr>
							<tr>
								<td>
									验收
								</td>
								<td>
									<s:hidden name="stockInStorage.acceptancerId"
										id="acceptancerId"></s:hidden>
									<s:textfield name="" id="acceptancerName" size="12" readonly="true"></s:textfield>
									<img src="<%=request.getContextPath()%>/images/kookup.gif"
										style="cursor: hand"
										onclick="multiSelect2('candiateName', 'candiateId', 'acceptancerName', 'acceptancerId', 'selectMultiCandiate.action', 'candiate', 700, 800, 0)">
								</td>

								<td>
									业务员
								</td>
								<td>
									<s:hidden name="stockInStorage.businesserId" id="businesserId"></s:hidden>
									<s:textfield name="" id="businesserName" size="12" readonly="true"></s:textfield>
									<img src="<%=request.getContextPath()%>/images/kookup.gif"
										style="cursor: hand"
										onclick="multiSelect2('candiateName', 'candiateId', 'businesserName', 'businesserId', 'selectMultiCandiate.action', 'candiate', 700, 800, 0)">
								</td>
								<td>
									摘要
								</td>
								<td colspan="4">
									<s:textfield name="stockInStorage.remark" size="40"></s:textfield>
								</td>
							</tr>
						</table>
						<hr>
					</div>
					<div class="sele" style="text-align: left; padding-left: 10px;">
						<input type="button" value="新增"
							onClick="addMaterialToStockInStorage()" onfocus="this.blur()"
							onMouseOver="this.className='btnover'"
							onmouseout="this.className='btnout'" class="btnsize" />
						<input type="button" value="删除" onClick="delrow()"
							onFocus="this.blur()" onMouseOver="this.className='btnover'"
							onmouseout="this.className='btnout'" class="btnsize" />
						<hr>
					</div>
					<!-- 信息显示栏 -->
					<div id="info_info4">
						<table id="info_table" width="1580px" cellspacing=1px
							cellpadding=1px class="sortable">
							<thead id="head">
								<tr>
									<th>
										<input type="checkbox" name="checkbox" onClick="selectAll()" />
									</th>
									<th width="100px">
										物料代码(*)
									</th>
									<th width="100px">
										物料名称
									</th>
									<th width="100px">
										规格型号
									</th>
									<th width="100px">
										收料仓库(*)
									</th>

									<th width="80px">
										批号
									</th>
									<th width="90px">
										单位(*)
									</th>
									<th width="90px">
										基本单位
									</th>
									<th width="60px">
										单价
									</th>
									<th width="90px">
										应收数量
									</th>
									<th width="120px">
										基本单位应收数量
									</th>
									<th width="90px">
										实收数量
									</th>
									<th width="120px">
										基本单位实收数量
									</th>
									<th width="50px">
										金额
									</th>
									<th width="120px">
										备注
									</th>
									<th width="100px">
										采购日期
									</th>
									<th width="80px">
										保质期(天)
									</th>
									<th width="110px">
										有效期至
									</th>
									<th width="90px">
										源单单号
									</th>
									<th width="100px">
										订单单号
									</th>
								</tr>
							</thead>
							<tbody id="mbody">

							</tbody>
							<tfoot>
								<tr>

								</tr>
							</tfoot>
						</table>
						<script language="javascript">  
						//("表格名称","奇数行背景","偶数行背景","点击后背景");
						 mouseclick("info_table","#ffffff","#ffffff","#e6f0fd");
						 //("表格名称","奇数行背景","偶数行背景");
						 //setcolor("t","#ffffff","#ffffff");
					</script>
					</div>
					<div style="margin: 6px; text-align: center;">
						<input type="submit" value="保存" onFocus="this.blur()"
							onMouseOver="this.className='btnover'"
							onmouseout="this.className='btnout'" class="btnsize" />
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<input type="button" value="返回" onClick="" onFocus="history.go(-1)"
							onMouseOver="this.className='btnover'"
							onmouseout="this.className='btnout'" class="btnsize" />
					</div>
				</div>
			</s:form>
		</div>
	</body>
</html>
